<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../vue.2.5.1.js"></script>
</head>

<body>
    <div id="sky">
        <input type="text" v-on:keyup.enter="addtodo" placeholder="请输入代办事项" v-model="inputValue">
        <ul>
            由于在ul中的组件名有限制，因此此处采用了is属性。
            <li is="all-list-zujian" v-for="(item,index) in items" v-bind:title='item' @removelist="items.splice(index,1)">

            </li>
        </ul>
    </div>
</body>
<script>
    Vue.component("all-list-zujian", {
        template: `<li>{{title}}<button v-on:click="$emit('removelist')">X</button></li>`,
        props: ["title"]
    })
    var app = new Vue({
        el: "#sky",
        data: {
            items: ['22'],
            inputValue: ""
        },
        methods: {
            addtodo() {
                this.items.push(this.inputValue);
                this.inputValue = ""
            }
        }
    })
</script>

</html>